package com.tqz.dt.attribute;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * <p>默认的事务属性
 *
 * @author tianqingzhao
 * @since 2021/7/7 14:40
 */
@Slf4j
@Data
public class DefaultGlobalTransactionAttribute implements GlobalTransactionAttribute {

    private String transactionManager;

    private String methodDescriptor;

    private int propagationBehavior = PROPAGATION_REQUIRED;

    private int isolationLevel = ISOLATION_DEFAULT;

    private int timeout = TIMEOUT_DEFAULT;

    private boolean readOnly = false;

    private List<Class<?>> rollbackFor;

    private List<Class<?>> noRollBackFor;

    @Override
    public String transactionManagerName() {
        return this.transactionManager;
    }

    @Override
    public boolean rollbackOn(Throwable ex) {
        return (ex instanceof Exception || ex instanceof Error);
    }

    @Override
    public int getPropagationBehavior() {
        return this.propagationBehavior;
    }

    @Override
    public int getIsolationLevel() {
        return this.isolationLevel;
    }

    @Override
    public int getTimeout() {
        return this.timeout;
    }

    @Override
    public boolean isReadOnly() {
        return this.readOnly;
    }

    @Override
    public String getName() {
        return this.methodDescriptor;
    }
}
